package com.devbobcorn.misaka.items;

import com.devbobcorn.misaka.entities.CoinEntity;

import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Stats;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;

public class CoinItem extends Item {
    public CoinItem(Properties settings) {
        super(settings);
    }
    
    // See SnowballItem.class
    public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
        ItemStack itemstack = player.getItemInHand(hand);
        world.playSound((PlayerEntity)null, player.getX(), player.getY(), player.getZ(), SoundEvents.SNOWBALL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
        
        if (!world.isClientSide) {
           CoinEntity coin = new CoinEntity(world, player);
           coin.setItem(itemstack);
           coin.shootFromRotation(player, player.xRot, player.yRot, 0.0F, 1.5F, 1.0F);
           world.addFreshEntity(coin);
        }
  
        player.awardStat(Stats.ITEM_USED.get(this));
        if (!player.abilities.instabuild) {
           itemstack.shrink(1);
        }
  
        return ActionResult.sidedSuccess(itemstack, world.isClientSide());
    }
}
